#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#include<unordered_set>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool vis[maxn],a[maxn];
vector<int>g[maxn];
int last=2;
void dfs(int u,int fa,vector<int>&nums)
{
    if(vis[u]) return;
    vis[u]=true;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        dfs(v,u,nums);
    }
    a[nums[u]]=1;
    while(1==a[last]) ++last;
}
vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {
    for(int i=0;i<parents.size();i++)
    {
        int fa=parents[i];
        if(fa==-1) continue;
        g[fa].push_back(i);
    }
    int pos=-1;
    int n=parents.size();
    vector<int>ans(n,1);
    for(int i=0;i<n;i++) if(nums[i]==1) pos=i;
    if(pos==-1) return ans;
    while(pos!=-1)
    {
        dfs(pos,parents[pos],nums);
        ans[pos]=last;
        pos=parents[pos];
    }
    return ans;
}
int main(void){

   	return 0;
}
